package com.rawm.gen.utils.generate;

import com.rawm.gen.common.Constant;
import com.rawm.gen.entity.Vo;
import com.rawm.gen.support.IGenerate;
import com.rawm.gen.utils.common.StrUtils;
import com.rawm.gen.utils.freemarker.FreeMarkerTemplateUtils;

import java.io.File;

/***
 *
 * @author: ZengXY
 * @date: 2023/5/24 15:22
 */
public class GenerateVo implements IGenerate<Vo> {
    @Override
    public void generateFile(Vo vo) throws Exception {
        final String path = StrUtils.getAbsolutePath()
                + Constant.SRC_PATH
                + StrUtils.package2path(vo.getPackageName() + Constant.DOT);
        final String templateName = "VO.ftl";
        File pat = new File(path);
        if (!pat.exists()) {
            pat.mkdirs();
        }
        String filePath = path + vo.getEntityName() + Constant.JAVA_SUFFIX;
        File file = new File(filePath);
        FreeMarkerTemplateUtils.generateFile(templateName, file, vo);
        System.out.println("Generate VO");
    }
}
